﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UDDL.Model;
using System.IO;

namespace UDDL.CodeGeneration.CPP
{
	class CppEntity : CppItem
	{
		internal CppEntity(CppNamespace parent, Entity source)
			: base(source)
		{
			Parent = parent;
			if (Parent.Filename == null)
			{
				Filename = Name;
			}
			else
			{
				Filename = Path.Combine(Parent.Filename, Name);
			}
			foreach (Property property in source.Properties)
			{
				m_properties.Add(new CppProperty(this, property));
			}
		}

		public void GenerateCode(CppFile file)
		{
			file.WriteLine("class {0}", Name);
			file.WriteLine("{{");
			file.WriteLine("private:");
			file.ChangeIdentation(1);
			foreach (CppProperty property in m_properties)
			{
				property.GenerateCode(file);
			}
			file.ChangeIdentation(-1);
			file.WriteLine("}};");
		}

		public String Filename { get; private set; }
		public CppNamespace Parent { get; internal set; }
		List<CppProperty> m_properties = new List<CppProperty>();
	}
}
